import { PDFResult } from '@/types/visualization/calculation'

// Color palette inspired by Sayu
export const COLOR_PANEL = ['#5b4846', '#8c5d42', '#da9464', '#809a54']

export const calcPDFResultMaxY = (data: PDFResult) => {
  let max = 0
  for (const pdf of Object.values(data)) {
    max = Math.max(max, Math.max(...Object.values(pdf as number[])))
  }
  return max
}

/**
 * 根据 ToolTip 的宽高和鼠标位置计算 ToolTip 的位置
 * @param element ToolTip 元素
 * @param event 鼠标事件
 */
export const calcTooltipLocation = (
  element: HTMLElement,
  event: MouseEvent,
) => {
  const tooltipWidth = element.offsetWidth
  const tooltipHeight = element.offsetHeight
  const x = event.clientX
  const y = event.clientY

  let left = x + 15
  let top = y + 15

  if (x + tooltipWidth + 20 > window.innerWidth) {
    left = x - tooltipWidth - 5
  }
  if (y + tooltipHeight + 20 > window.innerHeight) {
    top = Math.max(70, y - tooltipHeight - 5)
  }
  return { left, top }
}
